package intgrafica.principal;

import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class TelaCadastrarMedidas extends Activity {

	private EditText campoAltura;
	private EditText campoMassa;
	private EditText campoImc;
	private TextView campoSituacao;
	

	SQLiteDatabase bancoDeDados = null;
	String nomeBanco = "banco";

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.telacadastramedidas);
		
		

		campoAltura = (EditText) findViewById(R.id.editText12);
		campoMassa = (EditText) findViewById(R.id.editText1);
		campoImc = (EditText) findViewById(R.id.editText11);
		campoSituacao = (TextView) findViewById(R.id.textView14);

		Button proximo = (Button) findViewById(R.id.button2);
		proximo.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent it = new Intent(TelaCadastrarMedidas.this,
						TelaMedidasBraco.class);
				it.putExtra("altura", campoAltura.getText().toString());
				it.putExtra("peso", campoMassa.getText().toString());
				it.putExtra("imc", campoImc.getText().toString());
				it.putExtra("situacao", campoSituacao.getText().toString());
				startActivity(it);
			}
		});
		ImageButton voltar = (ImageButton) findViewById(R.id.imageButton2);
		voltar.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});

		Button calcularImc = (Button) findViewById(R.id.button1);
		calcularImc.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				calculaImc();
			}
		});

	}

	public void calculaImc() {
		Double Imc = Double.parseDouble(campoMassa.getText().toString())
				/ Math.pow(
						Double.parseDouble(campoAltura.getText().toString()), 2);
		campoImc.setText(Imc.toString());
		if (Imc < 18.5) {
			campoSituacao.setText("Abaixo do Peso!");
		} else if (Imc >= 18.5 && Imc < 24.9) {
			campoSituacao.setText("Peso Normal!");
		} else if (Imc >= 25.0 && Imc < 29.9) {
			campoSituacao.setText("Acima do Peso!");
		} else if (Imc >= 30.0 && Imc < 34.9) {
			campoSituacao.setText("Obsedidade grau I!");
		} else if (Imc >= 35.0 && Imc < 39.9) {
			campoSituacao.setText("Obsedidade grau II!");
		} else if (Imc >= 40.0) {
			campoSituacao.setText("Obsedidade grau III!");
		}

	}

	
}
